package com.mxx.v3.web.controller;

import com.github.pagehelper.PageInfo;
import com.mxx.v3.dto.*;
import com.mxx.v3.service.DeviceOeeService;
import com.mxx.v3.support.RestResponse;
import com.mxx.v3.utils.PageDto;
import com.mxx.v3.utils.PageQuery;
import com.mxx.v3.web.query.DeviceOee0Query;
import com.mxx.v3.web.query.DeviceOee2Query;
import com.mxx.v3.web.query.DeviceOeeQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program:report-from-server
 * @description:设备OEE报表
 * @author:AlTuring
 * @Date:2019/11/4-11:33
 **/
@RestController
@RequestMapping(value = "/deviceOee")
public class DeviceOeeController {
    @Autowired
    private DeviceOeeService deviceOeeService;
    /**
     * 设备OEE第一个报表
     * @param page
     * @param limit
     * @param deviceOeeQuery
     * @return
     */
    @GetMapping(value = "/report1")
    public RestResponse report1(Integer page, Integer limit, DeviceOeeQuery deviceOeeQuery){
        //封装查询条件
        PageQuery<DeviceOeeQuery> pageQuery = new PageQuery<>();
        pageQuery.setLimit(limit);
        pageQuery.setPage(page);
        pageQuery.setQueryItem(deviceOeeQuery);

        PageInfo<DeviceOeeDto> pageInfo = deviceOeeService.queryDeviceOee(pageQuery);
        PageDto<DeviceOeeDto> data = new PageDto<>(pageInfo.getTotal(), pageInfo.getList());

        return new RestResponse(data);
    }

    /**
     * 设备oee的第0个报表
     * @param page
     * @param limit
     * @param deviceOee0Query
     * @return
     */
    @GetMapping(value = "/report0")
    public RestResponse report0(Integer page, Integer limit, DeviceOee0Query deviceOee0Query){
        //封装查询条件
        PageQuery<DeviceOee0Query> pageQuery = new PageQuery<>();
        pageQuery.setLimit(limit);
        pageQuery.setPage(page);
        pageQuery.setQueryItem(deviceOee0Query);
        PageInfo<DeviceOeeStatusDto> pageInfo = deviceOeeService.queryDeviceOee0(pageQuery);
        PageDto<DeviceOeeStatusDto> data = new PageDto<>(pageInfo.getTotal(), pageInfo.getList());
        return new RestResponse(data);
    }
    /**
     * 设备oee的第0个报表
     * @param page
     * @param limit
     * @param deviceOee2Query
     * @return
     */
    @GetMapping(value = "/report2")
    public RestResponse report2(Integer page, Integer limit, DeviceOee2Query deviceOee2Query){
        //封装查询条件
        PageQuery<DeviceOee2Query> pageQuery = new PageQuery<>();
        pageQuery.setLimit(limit);
        pageQuery.setPage(page);
        pageQuery.setQueryItem(deviceOee2Query);
        PageInfo<DeviceMouthStatusDto> pageInfo = deviceOeeService.queryDeviceOee2(pageQuery);
        PageDto<DeviceMouthStatusDto> data = new PageDto<>(pageInfo.getTotal(), pageInfo.getList());
        return new RestResponse(data);
    }

    /**
     * 获取设备的所有分类
     * @return
     */
    @GetMapping(value = "/getdeviceclassify")
    public RestResponse getdeviceclassify(){
        //封装查询条件
        PageInfo<DeviceClassify> pageInfo = deviceOeeService.getDeviceClassify();
        PageDto<DeviceClassify> data = new PageDto<>(pageInfo.getTotal(), pageInfo.getList());
        return new RestResponse(data);
    }
}
